#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){
    
    circ1.set(ofRandom(ofGetWidth()), ofRandom(ofGetHeight()));
    circ2.set(ofRandom(ofGetWidth()), ofRandom(ofGetHeight()));
    
    radius1 = 200;
    radius2 = 120;
    
    vel1.set(1,1);
    vel2.set(-1,-1);
    
    ofBackground(0, 0, 0);
    
    circPtr = &circ1;
}

//--------------------------------------------------------------
void testApp::update(){
    
//    circ1 += vel1;
//    circ2 += vel2;
//    
//    if(circ1.x > ofGetWidth() || circ1.x < 0){
//        vel1.x *= -1;
//    }
//    if(circ2.x > ofGetWidth() || circ2.x < 0){
//        vel2.x *= -1;
//    }
//    if(circ1.y > ofGetHeight() || circ1.y < 0){
//        vel1.y *= -1;
//    }
//    if(circ2.y > ofGetHeight() || circ2.y < 0){
//        vel2.y *= -1;
//    }
    
    moveCirc(&circ1, &vel1);
    moveCirc(&circ2, &vel2);
    
    color.set(255);
    
    if(myDist(circ1, circ2) <= radius1 + radius2){
        color.set(255, 0, 0);
    }
}

//--------------------------------------------------------------
void testApp::draw(){
    ofSetColor(color);
               
    ofCircle(circ1, radius1);
    ofCircle(circ2, radius2);
    
    ofSetColor(0, 255, 0);
    //ofCircle(*circPtr, radius1/2);
    ofCircle(circPtr->x, circPtr->y, radius1/2);
}

//--------------------------------------------------------------
float testApp::moveCirc(ofPoint* p, ofVec2f* vel){
    *p += *vel;
    
    if(p->x > ofGetWidth() || p->x < 0){
        vel->x *= -1;
    }
    
    if(p->y > ofGetHeight() || p->y < 0){
        vel->y *= -1;
    }
}

//--------------------------------------------------------------
float testApp::myDist(ofPoint p1, ofPoint p2){
    return ofDist(p1.x, p1.y, p2.x, p2.y);
}


//--------------------------------------------------------------
void testApp::keyPressed(int key){
    if(key == 49){
        circPtr = &circ1;
    }
    
    if(key == 50){
        circPtr = &circ2;
    }
}

//--------------------------------------------------------------
void testApp::keyReleased(int key){

}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){

}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button){

}

//--------------------------------------------------------------
void testApp::windowResized(int w, int h){

}

//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg){

}

//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo){ 

}